 <script>
 	import {
 		saveLogin,
 		checkLogin,
 		getTicket
 	} from '@/utils/auth.js';
 	import request from '@/utils/request.js';

 	export default {
 		onLaunch: function() {
 			const loginPromise = new Promise(resolve => {
				const url = new URL(window.location.href);
				const ticket = url.searchParams.get('ticket') || getTicket();
				// 拿到ticket就去走登录接口
				if (ticket && !getTicket()) {
					saveLogin(ticket);
				}
				// 获取ticket
				if (checkLogin()) {
					request.post('/web/auth/login', {
						ticket
					}).then(res => {
						if (res.code === 0) {
							uni.setStorageSync('userInfo', res.data)
							uni.setStorageSync('userToken', res.data.token)
							this.$store.commit('m_user/saveUserInfo', res.data);
							resolve('');
						} else {
							uni.$showMsg(res.msg)
						}
					});
				}
			})
			this.globalData.loginPromise = loginPromise;
		},
 	    onShow: function() {},
 		onHide: function() {

 		}
 	}
 </script>

 <style>
 	page {
 		background-color: #eee;
 	}

 	/*每个页面公共css */
 </style>